import request from '@/utils/request';
import type { AxiosPromise } from 'axios';

/**
 * 用户查询对象
 */
export interface UserQuery extends PageQuery {
  phone?: string;
  nickname?: string;
  authStatus?: string;
  status?: string;
  beginTime?: string;
  endTime?: string;
}

/**
 * 用户对象
 */
export interface UserVO {
  userId: number;
  phone: string;
  nickname: string;
  avatar: string;
  gender: number;
  birthday: string;
  email: string;
  availableAmount: number;
  status: string;
  hasPayPassword: boolean;
  authStatus: string;
  // 实名认证信息（关联查询）
  realName?: string;       // 真实姓名
  docType?: string;        // 证件类型
  idCard?: string;         // 身份证号（脱敏）
  passportNo?: string;     // 护照号（脱敏）
  createTime: string;
  updateTime?: string;
}

/**
 * 用户表单对象
 */
export interface UserForm {
  userId?: number;
  phone: string;
  password?: string;
  payPassword?: string;
  nickname?: string;
  avatar?: string;
  gender?: number;
  birthday?: string;
  email?: string;
  availableAmount?: number;
  status?: string;
}

/**
 * 查询用户列表
 */
export function listUser(query: UserQuery): AxiosPromise<UserVO[]> {
  return request({
    url: '/admin/beauty/user/list',
    method: 'get',
    params: query
  });
}

/**
 * 查询用户详细
 */
export function getUser(userId: number): AxiosPromise<UserVO> {
  return request({
    url: `/admin/beauty/user/${userId}`,
    method: 'get'
  });
}

/**
 * 新增用户
 */
export function addUser(data: UserForm) {
  return request({
    url: '/admin/beauty/user',
    method: 'post',
    data: data
  });
}

/**
 * 修改用户
 */
export function updateUser(data: UserForm) {
  return request({
    url: '/admin/beauty/user',
    method: 'put',
    data: data
  });
}

/**
 * 删除用户
 */
export function delUser(userId: number | Array<number>) {
  return request({
    url: `/admin/beauty/user/${userId}`,
    method: 'delete'
  });
}

/**
 * 冻结用户
 */
export function freezeUser(userId: number) {
  return request({
    url: `/admin/beauty/user/freeze/${userId}`,
    method: 'put'
  });
}

/**
 * 解冻用户
 */
export function unfreezeUser(userId: number) {
  return request({
    url: `/admin/beauty/user/unfreeze/${userId}`,
    method: 'put'
  });
}

/**
 * 加入黑名单
 */
export function addToBlacklist(userId: number) {
  return request({
    url: `/admin/beauty/user/blacklist/${userId}`,
    method: 'put'
  });
}

/**
 * 移出黑名单
 */
export function removeFromBlacklist(userId: number) {
  return request({
    url: `/admin/beauty/user/removeBlacklist/${userId}`,
    method: 'put'
  });
}
